package org.lsms.servlet;

/**
 * servlet send email to reviewer to urge
 * @author ZhanXueliang
 * 2010.8.30
 */

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lsms.bean.User;
import org.lsms.dao.impl.DaoImpl;
import org.lsms.mail.MailSenderInfo;
import org.lsms.mail.SimpleMailSender;

public class send_email_to_urge extends HttpServlet {

	
	public void destroy() {
		super.destroy(); 
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			int user_id = Integer.parseInt(request.getParameter("user_id"));
			
			DaoImpl impl = new DaoImpl();
			
			User user = new User();
			user = impl.get_user_info(user_id);
			String email = user.getEmail();
			
			MailSenderInfo mailInfo = new MailSenderInfo();
			mailInfo.init(mailInfo);
			mailInfo.setToAddress(email);
			mailInfo.setSubject("This is a urge Email");
			
			SimpleMailSender sms = new SimpleMailSender();
			if(sms.sendTextMail(mailInfo)){
				String member_info = "The urge mail has been sent to " + user_id +"!"; 
				//request.setAttribute("member_info", member_info);
				response.sendRedirect("member/member_show_info.jsp?member_info="+member_info);
			}else{
				String member_info = "Email sending failed!Please try again later.";
				//request.setAttribute("member_info", member_info);
				response.sendRedirect("member/member_show_info.jsp?member_info="+member_info);
			}
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
